package com.zutassociation.web.controller.system;

import com.zutassociation.common.core.controller.BaseController;
import com.zutassociation.common.core.domain.AjaxResult;
import com.zutassociation.common.core.page.TableDataInfo;
import com.zutassociation.common.utils.SecurityUtils;
import com.zutassociation.system.domain.PlainReply;
import com.zutassociation.system.service.PlainReplyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 评论 信息操作处理
 *
 * @author 黄玉东
 * @version 1.0
 * @date 2021/4/20 21:13
 */
@RestController
@RequestMapping("/plainReply")
public class PlainReplyController extends BaseController {

    @Autowired
    private PlainReplyService replyService;

    /**
     * 获取评论列表
     */
//    @PreAuthorize("@ss.hasPermi('system:plainReply:list')")
    @GetMapping("/list")
    public TableDataInfo list(PlainReply reply) {
        startPage();
        List<PlainReply> list = replyService.selectReplyList(reply);
        return getDataTable(list);
    }

    /**
     * 根据发送人评论编号获取详细信息
     */
//    @PreAuthorize("@ss.hasPermi('system:plainReply:query')")
    @GetMapping(value = "/fromId/{fromId}")
    public AjaxResult getFromInfo(@PathVariable("fromId") Long fromId) {
        return AjaxResult.success(replyService.selectReplyFromId(fromId));
    }
    /**
     * 根据发送人评论编号获取详细信息
     */
//    @PreAuthorize("@ss.hasPermi('system:plainReply:query')")
    @GetMapping(value = "/toId/{toId}")
    public AjaxResult getToInfo(@PathVariable("toId") Long toId) {
        return AjaxResult.success(replyService.selectReplyToId(toId));
    }

    /**
     * 根据评论编号获取详细信息
     */
    //    @PreAuthorize("@ss.hasPermi('system:plainReply:query')")
    @GetMapping(value = "/{replyId}")
    public AjaxResult getInfo(@PathVariable("replyId") Long replyId) {
        return AjaxResult.success(replyService.selectReplyById(replyId));
    }

//    @PreAuthorize("@ss.hasPermi('system:plainReply:query')")
    @GetMapping(value = "/lastId/{lastId}")
    public AjaxResult getLastInfo(@PathVariable("lastId") Long lastId) {
        return AjaxResult.success(replyService.selectReplyByLastId(lastId));
    }

    //    @PreAuthorize("@ss.hasPermi('system:plainReply:query')")
    @GetMapping(value = "/contentId/{contentId}")
    public AjaxResult getcontentIdInfo(@PathVariable("contentId") Long contentId) {
        return AjaxResult.success(replyService.selectReplyContentId(contentId));
    }

    /**
     * 新增评论
     */
//    @PreAuthorize("@ss.hasPermi('system:plainReply:add')")
    @PostMapping
    public AjaxResult add(@Validated @RequestBody PlainReply reply) {
        reply.setCreateBy(SecurityUtils.getUsername());
        return toAjax(replyService.insertReply(reply));
    }

    /**
     * 修改评论
     */
//    @PreAuthorize("@ss.hasPermi('system:plainReply:edit')")
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody PlainReply reply) {
        reply.setUpdateBy(SecurityUtils.getUsername());
        return toAjax(replyService.updateReply(reply));
    }

    /**
     * 修改评论状态
     */
//    @PreAuthorize("@ss.hasPermi('system:plainReply:edit')")
    @PutMapping("/updateStatus")
    public AjaxResult updateStatus(@Validated @RequestBody PlainReply reply) {
        reply.setUpdateBy(SecurityUtils.getUsername());
        return toAjax(replyService.updateReplyStatus(reply));
    }

    /**
     * 修改评论举报状态
     */
//    @PreAuthorize("@ss.hasPermi('system:plainReply:edit')")
    @PutMapping("/updateReport")
    public AjaxResult updateReport(@Validated @RequestBody PlainReply reply) {
        reply.setUpdateBy(SecurityUtils.getUsername());
        return toAjax(replyService.updateReplyReport(reply));
    }


    /**
     * 浏览量+1
     */
//    @PreAuthorize("@ss.hasPermi('system:plainReply:edit')")
    @PutMapping("/updateClick")
    public AjaxResult updateClick(@Validated @RequestBody PlainReply reply) {
        return toAjax(replyService.updateReplyClick(reply));
    }
    /**
     * 点赞量+1
     */
//    @PreAuthorize("@ss.hasPermi('system:plainReply:edit')")
    @PutMapping("/updateFabulous")
    public AjaxResult updateFabulous(@Validated @RequestBody PlainReply reply) {
        return toAjax(replyService.updateReplyFabulous(reply));
    }
    @PutMapping("/updateNumber")
    public AjaxResult updateReplyNumber(@Validated @RequestBody PlainReply reply) {
        return toAjax(replyService.updateReplyNumber(reply));
    }

    /**
     * 删除评论
     */
//    @PreAuthorize("@ss.hasPermi('system:plainReply:remove')")
    @DeleteMapping("/{replyIds}")
    public AjaxResult remove(@PathVariable Long[] replyIds) {
        return toAjax(replyService.deleteReplyByIds(replyIds));
    }

    /**
     * 批量修改评论举报状态为 1 成功
     */
//    @PreAuthorize("@ss.hasPermi('system:plainReply:remove')")
    @DeleteMapping("/delReport1/{replyIds}")
    public AjaxResult deleteReport1(@PathVariable Long[] replyIds) {
        return toAjax(replyService.deleteReplyByReport1(replyIds));
    }

    /**
     * 批量修改评论举报状态为 2 不成功
     */
//    @PreAuthorize("@ss.hasPermi('system:plainReply:remove')")
    @DeleteMapping("/delReport2/{replyIds}")
    public AjaxResult deleteReport2(@PathVariable Long[] replyIds) {
        return toAjax(replyService.deleteReplyByReport2(replyIds));
    }

}
